package com.qf.day12;

import java.util.Scanner;

/**
 * @author wgy
 * @version V1.0
 * @Project day12
 * @Package com.qf.day12
 * @Description: ${TODO}
 * @Date 2021/6/2 10:55
 */
public class TestAnimal3 {
    public static void main(String[] args) {
        //主人
        Master shutong=new Master();
        shutong.setName("树桐");
        //领养动物
        Scanner input=new Scanner(System.in);
        System.out.println("-----------1.狗狗  2.猫咪-----------");
        System.out.println("请选择");
        int type=input.nextInt();
        Animal animal=shutong.adopt(type);
        if(animal!=null){
            System.out.println("领养成功");
            animal.show();
            //使用instanceof关键字判断对象的原始类型,避免类型转换异常
            if(animal instanceof Dog){
                Dog dog=(Dog) animal;
                dog.run();
            }else if(animal instanceof Cat){
                Cat cat=(Cat) animal;
                cat.play();
            }
        }else{
            System.out.println("领养失败");
        }
    }
}
